Skip to contentSkip to conversation

libyang: Fix CVE-2026-41401 and CVE-2026-44673

PATCH Knoetze, Juhandré 1 participant 2 messages Nov 2 – Nov 3 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 154 lines · Gunashree K L

From: Yunseong Kim<[email protected]>

Issue: LIN1026-7461

CVE-2026-41401:
Fix heap use-after-free in lyd_parser_set_data_flags() when freeing non-head default metadata entries. Ref:https://github.com/CESNET/libyang/commit/54c3276d871023da266d4ed3ceaee7e8d71d0b04 Ref:https://github.com/CESNET/libyang/security/advisories/GHSA-9f49-8x56-jmjc

CVE-2026-44673:
Fix integer overflow and OOM in lyb_read_string() and lyb_read_term_value() in the LYB binary parser. Ref:https://github.com/CESNET/libyang/commit/48672b289e2e4c6773712c3ee0abae6b7fffe1f3

---
  .../libyang/libyang/CVE-2026-41401.patch      | 41 +++++++++++
  .../libyang/libyang/CVE-2026-44673.patch      | 68 +++++++++++++++++++
  .../libyang/libyang_3.13.6.bb                 |  2 +
  3 files changed, 111 insertions(+)

create mode 100644 meta-oe/recipes-extended/libyang/libyang/CVE-2026-41401.patch create mode 100644 meta-oe/recipes-extended/libyang/libyang/CVE-2026-44673.patch

meta-oe/recipes-extended/libyang/libyang/CVE-2026-41401.patch new file +41 -0
new file mode 100644
index 0000000000..672fea92e6
@@ -0,0 +1,41 @@
+From 54c3276d871023da266d4ed3ceaee7e8d71d0b04 Mon Sep 17 00:00:00 2001
+From: Michal Vasko<[email protected]>
+Date: Thu, 26 Mar 2026 08:33:44 +0100
+Subject: [PATCH] parser common BUGFIX invalid metadata removal
+
+Upstream-Status: Backport [https://github.com/CESNET/libyang/commit/54c3276d871023da266d4ed3ceaee7e8d71d0b04]
+CVE: CVE-2026-41401
+
+Signed-off-by: Gunashree K L<[email protected]>
+---
+ src/parser_common.c                                    | 4 ++--
+ tests/fuzz/corpus/lyd_parse_mem_xml/advisory2026_03_26 | 5 +++++
+ 2 files changed, 7 insertions(+), 2 deletions(-)
+ create mode 100644 tests/fuzz/corpus/lyd_parse_mem_xml/advisory2026_03_26
+
+diff --git a/src/parser_common.c b/src/parser_common.c
+index 39fb4ab0a..f11fce560 100644
+--- a/src/parser_common.c
++++ b/src/parser_common.c
+@@ -313,8 +313,8 @@ lyd_parser_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, struct
+             next_meta = meta2->next;
+
+             /* delete the metadata */
+-            if (meta != &node->meta) {
+-                *meta = (*meta)->next;
++            if ((meta != &node->meta) && (meta2 == *meta)) {
++                *meta = next_meta;
+             }
+             lyd_free_meta_single(meta2);
+             if (prev_meta) {
+diff --git a/tests/fuzz/corpus/lyd_parse_mem_xml/advisory2026_03_26 b/tests/fuzz/corpus/lyd_parse_mem_xml/advisory2026_03_26
+new file mode 100644
+index 000000000..7e3b6c39e
+--- /dev/null
++++ b/tests/fuzz/corpus/lyd_parse_mem_xml/advisory2026_03_26
+@@ -0,0 +1,5 @@
++<int32 xmlns="urn:tests:types"
++xmlns:yang="urn:ietf:params:xml:ns:yang:1"
++xmlns:dflt="urn:ietf:params:xml:ns:netconf:default:1.0"
++yang:operation="create"
++dflt:default="true">5</int32>
meta-oe/recipes-extended/libyang/libyang/CVE-2026-44673.patch new file +68 -0
new file mode 100644
index 0000000000..2d685e111e
@@ -0,0 +1,68 @@
+From 48672b289e2e4c6773712c3ee0abae6b7fffe1f3 Mon Sep 17 00:00:00 2001
+From: dominik blain<[email protected]>
+Date: Wed, 6 May 2026 03:03:14 -0400
+Subject: [PATCH] parser lyb BUGFIX integer overflow and OOM (#2513)
+
+lyb_read_string: when len == UINT64_MAX, (len + 1) wraps to 0,
+malloc(0) returns non-NULL, and the subsequent write to (*str)[len]
+causes a WRITE SEGV (memory corruption).
+
+lyb_read_term_value: when term_value_len is large, truncation from
+uint64_t to uint32_t allocated_size causes undersized allocation
+followed by out-of-bounds write.
+
+Both paths are reachable by supplying a malformed LYB input with
+crafted length fields.
+
+Reported-by: Dominik Blain<[email protected]>, Cobalt AI
+
+CVE: CVE-2026-44673
+Upstream-Status: Backport [https://github.com/CESNET/libyang/commit/48672b289e2e4c6773712c3ee0abae6b7fffe1f3]
+
+Backport Changes:
+- Adapted for v2.1.148 code structure where lyb_read_string uses
+  uint64_t len (not uint32_t str_len) and lyb_read_term_value uses
+  uint32_t allocated_size with uint64_t term_value_len (not
+  lyb_read_value with val_size_bits).
+- Added overflow check for len in lyb_read_string to prevent wrap to 0.
+- Added overflow check for term_value_len in lyb_read_term_value to
+  prevent uint32_t truncation in allocated_size.
+
+(cherry picked from commit 48672b289e2e4c6773712c3ee0abae6b7fffe1f3)
+Signed-off-by: Yunseong Kim<[email protected]>
+Signed-off-by: Gunashree K L<[email protected]>
+
+---
+ src/parser_lyb.c | 10 ++++++++++
+ 1 file changed, 10 insertions(+)
+
+diff --git a/src/parser_lyb.c b/src/parser_lyb.c
+index 788be9499..c1cbfc805 100644
+--- a/src/parser_lyb.c
++++ b/src/parser_lyb.c
+@@ -217,6 +217,12 @@ lyb_read_string(char **str, uint8_t len_size, struct lylyb_ctx *lybctx)
+
+     lyb_read_number(&len, sizeof len, len_size, lybctx);
+
++    /* len + 1 wraps to 0 when len == UINT64_MAX, causing malloc(0) followed by an out-of-bounds write */
++    LY_CHECK_ERR_RET(len == UINT64_MAX,
++            LOGERR(lybctx->ctx, LY_EINVAL, "LYB string length overflow."), LY_EINVAL);
++    LY_CHECK_ERR_RET(len >= SIZE_MAX,
++            LOGERR(lybctx->ctx, LY_EINVAL, "LYB string length overflow."), LY_EINVAL);
++
+     *str = malloc((len + 1) * sizeof **str);
+     LY_CHECK_ERR_RET(!*str, LOGMEM(lybctx->ctx), LY_EMEM);
+
+@@ -281,6 +287,10 @@ lyb_read_term_value(const struct lysc_node_leaf *term, uint8_t **term_value, uin
+         *term_value_len = lyb_data_len;
+     }
+
++    /* Prevent uint32_t truncation: if term_value_len exceeds UINT32_MAX - 1, allocated_size overflows */
++    LY_CHECK_ERR_RET(*term_value_len >= UINT32_MAX,
++            LOGERR(lybctx->ctx, LY_EINVAL, "LYB value size overflow."), LY_EINVAL);
++
+     /* Allocate memory. */
+     allocated_size = *term_value_len + 1;
+     *term_value = malloc(allocated_size * sizeof **term_value);
+--
+2.43.0
meta-oe/recipes-extended/libyang/libyang_3.13.6.bb +0 -0
index 822c30ba24..1d84eb5c40 100644
@@ -10,6 +10,8 @@ SRCREV = "c2ddd01b9b810a30d6a7d6749a3bc9adeb7b01fb"
 
  SRC_URI ="git://github.com/CESNET/libyang.git;branch=master;protocol=https;tag=v${PV} 
Quoted 2 lines

\ file://0001-test_context-skip-test-case-test_searchdirs.patch \ + file://CVE-2026-41401.patch \ + file://CVE-2026-44673.patch \ file://run-ptest \ "

I don't have the RR cover letter for this review. Once I get the cover letter I can send the TA. :) It's possible the email is somewhere in my email folders but it wasn't in the thread with this patch.

../Juhandré

#2 lore raw
In reply to a message not in the archive
Quoted 3 lines · Gunashree K L

From: Yunseong Kim<[email protected]>

Issue: LIN1026-7461

Since this is an upstream patch, our internal issue numbering is not relevant. Please remove this before sending upstream, thank you!

../Juhandré

Quoted 153 lines

CVE-2026-41401:
Fix heap use-after-free in lyd_parser_set_data_flags() when freeing non-head default metadata entries. Ref:https://github.com/CESNET/libyang/commit/54c3276d871023da266d4ed3ceaee7e8d71d0b04 Ref:https://github.com/CESNET/libyang/security/advisories/GHSA-9f49-8x56-jmjc

CVE-2026-44673:
Fix integer overflow and OOM in lyb_read_string() and lyb_read_term_value() in the LYB binary parser. Ref:https://github.com/CESNET/libyang/commit/48672b289e2e4c6773712c3ee0abae6b7fffe1f3

---
  .../libyang/libyang/CVE-2026-41401.patch      | 41 +++++++++++
  .../libyang/libyang/CVE-2026-44673.patch      | 68 +++++++++++++++++++
  .../libyang/libyang_3.13.6.bb                 |  2 +
  3 files changed, 111 insertions(+)

create mode 100644 meta-oe/recipes-extended/libyang/libyang/CVE-2026-41401.patch create mode 100644 meta-oe/recipes-extended/libyang/libyang/CVE-2026-44673.patch

meta-oe/recipes-extended/libyang/libyang/CVE-2026-41401.patch new file +41 -0
new file mode 100644
index 0000000000..672fea92e6
@@ -0,0 +1,41 @@
+From 54c3276d871023da266d4ed3ceaee7e8d71d0b04 Mon Sep 17 00:00:00 2001
+From: Michal Vasko<[email protected]>
+Date: Thu, 26 Mar 2026 08:33:44 +0100
+Subject: [PATCH] parser common BUGFIX invalid metadata removal
+
+Upstream-Status: Backport [https://github.com/CESNET/libyang/commit/54c3276d871023da266d4ed3ceaee7e8d71d0b04]
+CVE: CVE-2026-41401
+
+Signed-off-by: Gunashree K L<[email protected]>
+---
+ src/parser_common.c                                    | 4 ++--
+ tests/fuzz/corpus/lyd_parse_mem_xml/advisory2026_03_26 | 5 +++++
+ 2 files changed, 7 insertions(+), 2 deletions(-)
+ create mode 100644 tests/fuzz/corpus/lyd_parse_mem_xml/advisory2026_03_26
+
+diff --git a/src/parser_common.c b/src/parser_common.c
+index 39fb4ab0a..f11fce560 100644
+--- a/src/parser_common.c
++++ b/src/parser_common.c
+@@ -313,8 +313,8 @@ lyd_parser_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, struct
+             next_meta = meta2->next;
+
+             /* delete the metadata */
+-            if (meta != &node->meta) {
+-                *meta = (*meta)->next;
++            if ((meta != &node->meta) && (meta2 == *meta)) {
++                *meta = next_meta;
+             }
+             lyd_free_meta_single(meta2);
+             if (prev_meta) {
+diff --git a/tests/fuzz/corpus/lyd_parse_mem_xml/advisory2026_03_26 b/tests/fuzz/corpus/lyd_parse_mem_xml/advisory2026_03_26
+new file mode 100644
+index 000000000..7e3b6c39e
+--- /dev/null
++++ b/tests/fuzz/corpus/lyd_parse_mem_xml/advisory2026_03_26
+@@ -0,0 +1,5 @@
++<int32 xmlns="urn:tests:types"
++xmlns:yang="urn:ietf:params:xml:ns:yang:1"
++xmlns:dflt="urn:ietf:params:xml:ns:netconf:default:1.0"
++yang:operation="create"
++dflt:default="true">5</int32>
meta-oe/recipes-extended/libyang/libyang/CVE-2026-44673.patch new file +68 -0
new file mode 100644
index 0000000000..2d685e111e
@@ -0,0 +1,68 @@
+From 48672b289e2e4c6773712c3ee0abae6b7fffe1f3 Mon Sep 17 00:00:00 2001
+From: dominik blain<[email protected]>
+Date: Wed, 6 May 2026 03:03:14 -0400
+Subject: [PATCH] parser lyb BUGFIX integer overflow and OOM (#2513)
+
+lyb_read_string: when len == UINT64_MAX, (len + 1) wraps to 0,
+malloc(0) returns non-NULL, and the subsequent write to (*str)[len]
+causes a WRITE SEGV (memory corruption).
+
+lyb_read_term_value: when term_value_len is large, truncation from
+uint64_t to uint32_t allocated_size causes undersized allocation
+followed by out-of-bounds write.
+
+Both paths are reachable by supplying a malformed LYB input with
+crafted length fields.
+
+Reported-by: Dominik Blain<[email protected]>, Cobalt AI
+
+CVE: CVE-2026-44673
+Upstream-Status: Backport [https://github.com/CESNET/libyang/commit/48672b289e2e4c6773712c3ee0abae6b7fffe1f3]
+
+Backport Changes:
+- Adapted for v2.1.148 code structure where lyb_read_string uses
+  uint64_t len (not uint32_t str_len) and lyb_read_term_value uses
+  uint32_t allocated_size with uint64_t term_value_len (not
+  lyb_read_value with val_size_bits).
+- Added overflow check for len in lyb_read_string to prevent wrap to 0.
+- Added overflow check for term_value_len in lyb_read_term_value to
+  prevent uint32_t truncation in allocated_size.
+
+(cherry picked from commit 48672b289e2e4c6773712c3ee0abae6b7fffe1f3)
+Signed-off-by: Yunseong Kim<[email protected]>
+Signed-off-by: Gunashree K L<[email protected]>
+
+---
+ src/parser_lyb.c | 10 ++++++++++
+ 1 file changed, 10 insertions(+)
+
+diff --git a/src/parser_lyb.c b/src/parser_lyb.c
+index 788be9499..c1cbfc805 100644
+--- a/src/parser_lyb.c
++++ b/src/parser_lyb.c
+@@ -217,6 +217,12 @@ lyb_read_string(char **str, uint8_t len_size, struct lylyb_ctx *lybctx)
+
+     lyb_read_number(&len, sizeof len, len_size, lybctx);
+
++    /* len + 1 wraps to 0 when len == UINT64_MAX, causing malloc(0) followed by an out-of-bounds write */
++    LY_CHECK_ERR_RET(len == UINT64_MAX,
++            LOGERR(lybctx->ctx, LY_EINVAL, "LYB string length overflow."), LY_EINVAL);
++    LY_CHECK_ERR_RET(len >= SIZE_MAX,
++            LOGERR(lybctx->ctx, LY_EINVAL, "LYB string length overflow."), LY_EINVAL);
++
+     *str = malloc((len + 1) * sizeof **str);
+     LY_CHECK_ERR_RET(!*str, LOGMEM(lybctx->ctx), LY_EMEM);
+
+@@ -281,6 +287,10 @@ lyb_read_term_value(const struct lysc_node_leaf *term, uint8_t **term_value, uin
+         *term_value_len = lyb_data_len;
+     }
+
++    /* Prevent uint32_t truncation: if term_value_len exceeds UINT32_MAX - 1, allocated_size overflows */
++    LY_CHECK_ERR_RET(*term_value_len >= UINT32_MAX,
++            LOGERR(lybctx->ctx, LY_EINVAL, "LYB value size overflow."), LY_EINVAL);
++
+     /* Allocate memory. */
+     allocated_size = *term_value_len + 1;
+     *term_value = malloc(allocated_size * sizeof **term_value);
+--
+2.43.0
meta-oe/recipes-extended/libyang/libyang_3.13.6.bb +0 -0
index 822c30ba24..1d84eb5c40 100644
@@ -10,6 +10,8 @@ SRCREV = "c2ddd01b9b810a30d6a7d6749a3bc9adeb7b01fb"
 
  SRC_URI ="git://github.com/CESNET/libyang.git;branch=master;protocol=https;tag=v${PV} 

\ file://0001-test_context-skip-test-case-test_searchdirs.patch \ + file://CVE-2026-41401.patch \ + file://CVE-2026-44673.patch \ file://run-ptest \ "